/*
 * COPYRIGHT:	2010 Christopher Smith, licenced under the GNU GPL v2; see COPYING in the top level directory
 * PROJECT:		sdedit
 * FILE:		sdeditg build.cpp
 * PURPOSE:		Compilation unit for the SD Edit GUI target (sdeditg.exe)
 *				Includes all necessary headers and source
 */

//#define _UNICODE //defined in project properties
//#define UNICODE

#define _USE_MATH_DEFINES

#define WIN32_LEAN_AND_MEAN
//#define _NTDEF_

#define STRICT

#include <crtdbg.h> //only used in debug builds

//needed for certain optional header items, and because versions that are too old have broken headers
//actual earliest supported target (minus LDAP) is NT3.51 SP5. Support for the few optional things is detected at runtime and delay loaded.
#define _WIN32_WINNT 0x0600
#define _WIN32_IE 0x0800

#define WIN32_NO_STATUS //we want the full set from ntstatus.h instead
#include <windows.h> //main windows header
#undef WIN32_NO_STATUS

#include <ntstatus.h> //NT status codes used in several places
#include <stdlib.h>
#include <stdarg.h>
#include <delayimp.h>

#include <math.h> //for sin()
#include <wchar.h>
#include <commctrl.h>

#define _DS_CONTROL_BITS_DEFINED_ //we want the full set from ntdsapi.h instead
#include <Aclapi.h>
#undef _DS_CONTROL_BITS_DEFINED_

#define SECURITY_WIN32
#include <sspi.h>

#include <ntdsapi.h>

#include <Winldap.h>
#include <Ntldap.h>
#include <Winber.h>

#include <Dsgetdc.h> //for the constants
#include <Dsrole.h>

#include "ntapi.cpp"

#define _NTDEF_ //to avoid silly LSA_* prefixed structures
#include <Ntsecapi.h>
#include <lm.h>

#include <eh.h>

#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0351 //actual min supported version
#include <atlbase.h>
#include <aclui.h>
#include <prsht.h>

//begin SD Edit source
#include "cast.cpp"

#include "resource.h"

#include "winhelp.h"

#include "type limits.cpp"

HMODULE SdEditGModule; //pointer to the base address of this module

#include "auto common.cpp"
#include "auto_szpod.cpp"
#include "auto_ptr.cpp"
#include "auto_refct.cpp"
#include "auto_array.cpp"
#include "auto_buffer.cpp"
#include "auto_free.cpp"

static const ULONG MAX_STRING_CHARS				= 0x7FE; //maximum characters expected for a message string
static const ULONG MAX_SID_BYTES				= sizeof(SID) + sizeof(ULONG) * SID_MAX_SUB_AUTHORITIES; //maximum number of bytes in a SID
static const ULONG DIRECTORY_QUERY_BUFFER_SIZE	= 0x1000; //default bulk directory query buffer
static const USHORT ACL_BUFFER_SIZE_DEFAULT		= 0x100; //default ACL buffer; must be at least sizeof(ACL)
static const ULONG TOKEN_INFO_SIZE_DEFAULT		= 0x100; //default token buffer

static const UINT WM_PRE_PROCESS				= WM_APP + 0x1000;

static const UCHAR DESC_SPECIFIC_SIZE			= 0x10; //number of bits in an ACCESS_MASK for type-specific rights

#define HANDLE_ALL_EXCEPTIONS					0 //not to be enabled for release

#include "rtl.cpp"

#include "sehexpt.cpp"
#include "winhelp cpp.cpp"

#include "sdedit cppstruct.cpp"
#include "auto opts.cpp"
#include "sdedit rtl.cpp"
#include "sdconv.cpp"

#include "msgloop.cpp"

#include "delayed import.cpp"

#include "privileges.cpp"
#include "lookup.cpp"
#include "lookup multi.cpp"
#include "workqueue.cpp"
#include "dialogcallback.cpp"
#include "sidtext.cpp"

#include "objtypes.cpp"
#include "sdmerge.cpp"
#include "objcontainertypes.cpp"

#include "module.cpp"

#include "netapi opts.cpp"
#include "netapi.cpp"

#include "ntapi tc types.cpp"
#include "ntapi tc module.cpp"

#include "win32 tc types.cpp"
#include "win32 tc module.cpp"

#include "lsa opts.cpp"
#include "lsa.cpp"
#include "lsa tc.cpp"
#include "lsa module.cpp"

#include "ntds ldap opts.cpp"
#include "ntds ldap.cpp"
#include "ntds ldap enum sid.cpp"
#include "ntds ldap enum guid.cpp"
#include "ntds ldap lookup sid.cpp"
#include "ntds ldap lookup guid.cpp"
#include "ntds ldap tc.cpp"
#include "ntds ldap module.cpp"

#include "opt reg.cpp"
#include "cmdline.cpp"

#include "winbase.cpp"
#include "clswinbase.cpp"
#include "subclswinbase.cpp"
#include "dialogbase.cpp"
#include "popupbase.cpp"

#include "opts gui.cpp"
using GuiOpt::SDE_GUI_PREFS;

#include "editpopup.cpp"
#include "editenter.cpp"
#include "menu enum.cpp"
#include "acleditor.cpp"
#include "errordialog.cpp"

#include "sdeditor.cpp"

#include "errortaskdialog.cpp"

#include "sdeditg shellinst.cpp"

void __stdcall DBG_CheckAllocs();

#include "sdeditg dll.cpp"

#include "sdeditg main.cpp"
#include "acluialt ppage.cpp"
#include "acluialt editsecurity.cpp"